/* 内河涌 弹框 建筑物信息页 
 * @ 劳兆城 
 * @ 2017-08-12*/

<template>
	<div class="water-build">
		<div class="build-box">
			<div class="build-row">
				<div class="build-title">堤防桩号</div>
				<div class="build-content">
					<Input 
						v-model="search.pilenum" 
						size="small" 
						placeholder="请输入"
						></Input>
				</div>
			</div>
			<div class="build-row">
				<div class="build-title">建筑物名称</div>
				<div class="build-content">
					<Input 
						v-model="search.building" 
						size="small" 
						placeholder="请输入"
						></Input>
				</div>
			</div>
			<div class="build-row">
				<div class="build-search">
					<Button @click.native="searchClick" type="text">查询</Button>
				</div>
			</div>
		</div>
		<div class="build-table">
			<div class="table">
				<Table 
					:columns="table.thead" 
					:data="table.tbody" 
					size="small" 
					highlight-row 
					></Table>
			</div>
			<div class="page">
				<Page 
				@on-change="pageChange" 
				:total="table.total" 
				size="small" 
				show-total ></Page>
			</div>
		</div>
	</div>
</template>

<script>
	import { singleWaterNetBuild } from 'common/js/table'
import { successNotice, errorNotice } from 'common/js/dom'
import { ERR_OK } from 'api/config'
import { getWaterBuild, delWaterBuild } from 'api/aPicture'

export default {
		created () {
			this.page = 1
		this._getWaterBuild()
	},
		data () {
			return {
				search: {
					pilenum: '',
					building: ''
				},
				table: {
					thead: singleWaterNetBuild(this),
					tbody: [],
					total: null
				}
			}
		},
		methods: {
			searchClick () {
				let obj = {}
			for (let key in this.search) {
					if (this.search[key]) {
						obj[key] = this.search[key]
					this.search[key] = ''
				}
				}
				if (JSON.stringify(obj) === '{}') {
					return
			}
				this._getWaterBuild(1, obj)
		},
			pageChange (page) {
				this.page = page
			this._getWaterBuild(page)
		},
			_delClick (row) {
				delWaterBuild(row.buildid).then(res => {
					if (res.code === ERR_OK) {
						this._getWaterBuild(this.page)
					successNotice('删除成功')
				} else {
						errorNotice('删除失败')
				}
				})
			},
			_getWaterBuild (page, data) {
				getWaterBuild(page, data).then(res => {
					if (res.code === ERR_OK) {
						this.table.tbody = res.result.result
					this.table.total = res.result.totalSize
				}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.singleWaterNet-model {
		.water-build {
			width: 100%;
			height: 100%;
			padding: 0 5px;
			.build-box {
				width: 600px;
				display: flex;
				.build-row {
					flex: 1;
					display: flex;
					align-items:center;
					margin: 5px 0;
					.build-title {
						width: 70px;
						font-size: 12px;
						text-align: right;
						padding-right: 5px;
						margin-top: 2px;
					}
					.build-content {
						flex: 1;
					}
					.build-search {
						position: relative;
						top: 1px;	
					}
				}
			}
			.build-table {
				width: 100%;
				height: calc(100% - 47px);
				position: relative;
				margin-right: 10px;
				.table {
					width: 100%;
					position: absolute;
					top: 0px;
					left: 0;
					bottom: 30px;
				}
				.page {
					position: absolute;
					bottom: 5px;
					right: 5px;
				}
			}
		}
	}
</style>